package object;

import org.testng.annotations.Test;

/**
 *
 * @author
 */
public class ClassCast {

    /**
     * 父类对象强转成子类对象
     */
    @Test
    private void t1() {
        Father f1 = new Father();

        //
        ((Son) f1).setAge(2);

        Father father = new Son();

        Son s2 = new Son();


    }

    static class Father {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    static class Son extends Father {
        private int age;

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
